﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;
using System.Data.SqlClient;
namespace DAO
{
    public class KhoDAO
    {
        ConnectDB conn = new ConnectDB();
        string str;
        //Load dữ liệu
        public DataTable LoadKho()
        {
            return conn.LayDuLieu("select *from Kho");
        }
        // insert va update
        public void IsUp_Kho(KhoDTO p, bool flag)
        {
            string makho=p.MaKho ;
            string Tenkho=p.TenKho ;
            float sl=p.SoLuongHienTai ;
            float qd=p.SoLuongQuyDinh ;
             if(flag==true )
            {//(MaHD, MaSP, MaKH, MaKH, SoLuong, TongTien, NgayMua, MaNV, GiaBan)
                str = "INSERT Kho(TenKho, SoLuongHienTai, SoLuongQuyDinh)  VALUES('"+ Tenkho +"',"+ sl +","+ qd +")";
            }
            else
            {
                str ="UPDATE Kho SET TenKho ='"+ Tenkho +"', SoLuongHienTai ="+ sl + ", SoLuongQuyDinh ="+ qd +" WHERE MaKho='"+ makho +"'";
            }
            conn.excute(str);
        }
        //del
        public void Del_Kho(KhoDTO p)
        {
            string makho = p.MaKho ;
            str = "DELETE Kho WHERE MaKho='" + makho + "'";
            conn.excute(str);
        }
        //Tim kiem

        public DataTable TimKho(KhoDTO p, Boolean flag)
        {
            string makho = p.MaKho;
            string Tenkho = p.TenKho;
            if (flag == true)
            {
                str = "select * from Kho where MaKho like'%" + makho  + "%'";
            }
            else
            {
                str = "select * from Kho where TenKho like'%" + Tenkho  + "%'";
            }
            return conn.LayDuLieu(str);

        }
    }
}
